package file

import (
	"bytes"
	"encoding/json"
	"io"
	"net/http"
	"os"

	"github.com/sirupsen/logrus"
)

type Fileput struct {
	Id          string `json:"id"`
	Starget     string `json:"starget"`
	DTarget     string `json:"dtarget"` //目标目录
	Address     string `json:"address"` //目标位置
	Filesteam   []byte `json:"filesteam"`
	Filename    string `json:"filename"`
	Command     string `json:"command"`     //执行命令  部署相关
	Subname     string `json:"subname"`     //项目名称
	FrontOrBack string `json:"frontorback"` //前后端区分
	FilePutName string `json:"fpn"`
}

func (f Fileput) POST(l *logrus.Logger) {
	jsonfData, _ := json.Marshal(f)
	jsonf := bytes.NewReader(jsonfData)
	resp, err := http.Post("http://"+f.Address+":20091/clicmd", "application/json", jsonf)
	if err != nil {
		l.Error("转发错误", err)
	}
	respb, _ := io.ReadAll(resp.Body)
	l.Info(string(respb))
}
func (f Fileput) BackSteam() Fileput {
	var err error
	f.Filesteam, err = os.ReadFile(f.Starget)
	if err != nil {
		panic(err)
	}
	return f
}
